package com.jfcloud.mall.order.domain.dto;

import java.util.ArrayList;
import java.util.List;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class OrderSubmitForm {
	
	@ApiModelProperty(value = "API token",required = true)
	private String token;
	
	
	@ApiModelProperty(value = "订单明细",required = true)
	private List<OrderDetail> details;
	
	@Data
	public static class OrderDetail {
		@ApiModelProperty(value = "商品的id",required = true)
	    private Long productId;
		
		@ApiModelProperty(value = "商品数量",required = true)
	    private Integer productNum;
	}
	
	public Integer aclPrdNum() {
		Integer r=0;
		if(details!=null) {
			for(OrderDetail p:details) {
				r+=p.getProductNum();
			}
		}
		return r;
	}

	public String aclPrdIds() {
		String r="";
		if(details!=null) {
			for(OrderDetail p:details) {
				r+=p.getProductId()+",";
			}
		}
		return r;
	}

	public List<Long> aclPrdList(){
		List<Long> ids = new ArrayList<Long>();
		if(details!=null){
			details.forEach(p->ids.add(p.getProductId()));
		}
		return ids;
	}
	
}
